package com.indsvr.service;

import com.google.gson.Gson;
import com.indsvr.entity.xunlei.XunLeiTask;
import com.indsvr.utils.XunleiOkHttpUtils;
import org.springframework.stereotype.Service;

import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;

@Service
public class RecordService {

    //filters:  "PHASE_TYPE_COMPLETE,PHASE_TYPE_PENDING,PHASE_TYPE_RUNNING,PHASE_TYPE_PAUSED,PHASE_TYPE_ERROR"
    public ArrayList<XunLeiTask.Task> getRecord(XunleiOkHttpUtils xunleiOkHttpUtils) throws Exception{
        String url = "/drive/v1/tasks";
        HashMap<String, String> params = new HashMap<>();
        params.put("limit","100");
        params.put("page_token","");
        params.put("filters","{\"phase\":{\"in\":\"PHASE_TYPE_COMPLETE,PHASE_TYPE_PENDING,PHASE_TYPE_RUNNING,PHASE_TYPE_PAUSED,PHASE_TYPE_ERROR\"},\"type\":{\"in\":\"user#download-url,user#download\"}}");
        String execute = xunleiOkHttpUtils.execute(url, params, null);
        XunLeiTask xunLeiTask = new Gson().fromJson(execute, XunLeiTask.class);
        ArrayList<XunLeiTask.Task> tasks = xunLeiTask.getTasks();
        return tasks;
    }


}
